package splash.core.connection;

import splash.core.security.User;

import splash.core.Util;

public class Session
{
	private String ssid;
	private boolean authenticated;
        private User user;
        private long expire;
	
	private Session()
	{
		generate();
	}

	public static Session create()
	{
		return new Session();
	}
	
	public String getSSID()
	{
		return this.ssid;
	}
	
	public void setSSID(String ssid)
	{
		this.ssid = ssid;
	}
	
	public boolean getAuth()
	{
		return this.authenticated;
	}
	
	public void setAuth(boolean auth)
	{
		this.authenticated = auth;
	}

        public void setUser(User u)
        {
            if(this.user != null && u != null)
                this.user = u;
        }

        public User getUser()
        {
            return this.user;
        }

        public long getExpire()
        {
            return this.expire;
        }

	public String generate()
	{
		this.ssid = Util.md5("" + (int)(Math.random() * 100000));
		this.authenticated = false;
                this.user = null;
                this.expire = System.currentTimeMillis() + (3600 * 1000);
		return this.ssid;
	}
}